<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .container {
            width: 400px;
            margin: 50px auto 0;
            /* transform: translate(-50) */
            background-color: rgb(202, 200, 200);
        }
        
        .box {
            margin: 0 auto;
            width: 100px;
            height: 100px;
            background-color: rgb(71, 37, 37);
            transition: 0.3s;
        }
        
        .blue {
            background-color: rgb(108, 106, 206);
        }
        
        .hidden {
            visibility: hidden;
        }
    </style>
</head>

<body>
    <div class="container">
        <button class="btn w">变宽</button>
        <button class="btn h">变高</button>
        <button class="btn c">改变颜色</button>
        <button class="btn hi">隐藏</button>
        <div class="box"></div>
    </div>

    <script>
        var box = document.querySelector('.box')
        var btns = document.querySelectorAll('.btn')
        btns[0].addEventListener('click', function(e) {
            box.style.width = "200px";
        })
        btns[2].addEventListener('click', function(e) {
            box.classList.toggle('blue')

        })
        btns[3].addEventListener('click', function(e) {
            box.classList.toggle('hidden')
        })
        onclick = function(e) {
            console.log(e)
        }
        onkeypress = function(e) {
            console.log(e)
        }
    </script>
</body>

</html>